<template>
    <div :class="['phone-model', drawer ? 'showPhone' : '']">
      <div class="model-bg" @click="hidePage"></div>
      <div class="phone-model-container">
          <div class="phone-title">详情预览</div>
          <el-scrollbar style="height:600px;">
              <div class="phone-container">
                  <el-carousel trigger="click" height="200px" :loop="true">
                      <el-carousel-item v-for="item in defaultForm.images" :key="item">
                          <el-image :src="item" fit="cover" style="width: 100%;height:200px"></el-image>
                      </el-carousel-item>
                  </el-carousel>
                  <p class="title">{{defaultForm.name}}</p>
                  <p class="price"><span class="unit">￥</span>{{defaultForm.price == null?0:defaultForm.price}}</p>
                  <div class="other_data">
                      <span class="other_cell">原价:￥{{defaultForm.originPrice == null?0:defaultForm.originPrice}}</span>
                      <span class="other_cell">库存:{{defaultForm.stock == null?0:defaultForm.stock}}件</span>
                      <span class="other_cell">销量:{{defaultForm.sale == null?0:defaultForm.sale}}件</span>
                  </div>
                  <div class="detail-content">
                      <p class="detail-title">商品详情</p>
                      <div class="detail-html" v-html="defaultForm.desc"></div>
                  </div>
              </div>
          </el-scrollbar>
      </div>
    </div>
</template>

<script>
import { toRefs, computed } from 'vue'
export default {
    name: 'PhoneModel',
    props: {
        dialogDrawer: {
            type: Boolean,
            default: false
        },
        defaultForm: {
            type: Object,
            default() {
                return {}
            }
        }
    },
    setup(props, context) {
        const { dialogDrawer } = toRefs(props)
        const drawer = computed({
            get: () => dialogDrawer.value,
            set: val => {
                context.emit('update:dialogDrawer', val)
            }
        })
        const hidePage = () => {
            context.emit('update:dialogDrawer', false)
        }
        return {
            drawer,
            hidePage
        }
    }
}
</script>

<style scoped lang="scss">
.phone-model {
    position: relative;
    width: 100%;
    height: 100%;
    display: none;
    .model-bg{
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 9999;
        background: rgba(0,0,0,.2);
    }
    .phone-model-container{
        position: fixed;
        left: 0;
        right: 0;
        top: 0;
        bottom: 0;
        width: 375px;
        height: 667px;
        border-radius: 16px;
        box-shadow: rgba(0, 0, 0, 0.05) 0px 6px 24px 0px, rgba(0, 0, 0, 0.08) 0px 0px 0px 1px;
        background: #fff;
        z-index: 99999;
        margin: auto;
        .phone-title{
            text-align: center;
            font-size: 18px;
            padding: 10px 0;
        }
        .phone-container{
            height: calc(100% - 50px);
            overflow-y: auto;
            p{
                line-height: normal;
            }
            .title{
                padding: 10px;
                color: #333;
                word-wrap: break-word;
                word-break: break-all;
                font-weight: bold;
                font-size: 14px;
            }
            .price{
                text-align: right;
                color: crimson;
                font-size: 20px;
                padding-right: 10px;
                line-height: normal;
                .unit{
                    font-size: 12px;
                }
            }
            .other_data{
                display: flex;
                justify-content: space-between;
                align-items: center;
                padding: 10px 10px 0;
                .other_cell{
                    font-size: 14px;
                    color: #909399;
                }
            }
            .detail-content{
                padding: 10px 10px 0;
                border-top: 1px solid #eee;
                margin-top: 10px;
                .detail-title{
                    font-size: 16px;
                    text-align: center;
                    line-height: normal;
                }
                .detail-html{
                    word-break: break-all;
                    line-height: normal;
                    margin-top: 8px;
                    :deep(img) {
                        max-width: 100% !important;
                        object-fit: contain;
                    }
                }
            }
        }
    }
}
.showPhone{
    display: block;
}
</style>
